package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.support.DOM4JTest;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YktAccessEvent;
import com.ruoyi.system.service.IYktAccessEventService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门禁事件记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-10
 */
@Controller
@RequestMapping("/system/event")
public class YktAccessEventController extends BaseController
{
    @Autowired
    private DOM4JTest dom4jTest;

    private String prefix = "system/event";

    @Autowired
    private IYktAccessEventService yktAccessEventService;

    @RequiresPermissions("system:event:view")
    @GetMapping()
    public String event()
    {
        return prefix + "/event";
    }

    /**
     * 查询门禁事件记录列表
     */
    @RequiresPermissions("system:event:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YktAccessEvent yktAccessEvent)
    {
//        dom4jTest.parseXml();
        startPage();
        List<YktAccessEvent> list = yktAccessEventService.selectYktAccessEventList(yktAccessEvent);
        return getDataTable(list);
    }

    /**
     * 导出门禁事件记录列表
     */
    @RequiresPermissions("system:event:export")
    @Log(title = "门禁事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YktAccessEvent yktAccessEvent)
    {
        List<YktAccessEvent> list = yktAccessEventService.selectYktAccessEventList(yktAccessEvent);
        ExcelUtil<YktAccessEvent> util = new ExcelUtil<YktAccessEvent>(YktAccessEvent.class);
        return util.exportExcel(list, "门禁事件记录数据");
    }

    /**
     * 新增门禁事件记录
     */
    @RequiresPermissions("system:event:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存门禁事件记录
     */
    @RequiresPermissions("system:event:add")
    @Log(title = "门禁事件记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YktAccessEvent yktAccessEvent)
    {
        return toAjax(yktAccessEventService.insertYktAccessEvent(yktAccessEvent));
    }

    /**
     * 修改门禁事件记录
     */
    @RequiresPermissions("system:event:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        YktAccessEvent yktAccessEvent = yktAccessEventService.selectYktAccessEventById(id);
        mmap.put("yktAccessEvent", yktAccessEvent);
        return prefix + "/edit";
    }

    /**
     * 修改保存门禁事件记录
     */
    @RequiresPermissions("system:event:edit")
    @Log(title = "门禁事件记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YktAccessEvent yktAccessEvent)
    {
        return toAjax(yktAccessEventService.updateYktAccessEvent(yktAccessEvent));
    }

    /**
     * 删除门禁事件记录
     */
    @RequiresPermissions("system:event:remove")
    @Log(title = "门禁事件记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yktAccessEventService.deleteYktAccessEventByIds(ids));
    }
}
